import { NextRequest, NextResponse } from 'next/server';
import { getToolById } from '@/lib/db';
export async function GET(request: NextRequest, { params }: { params: { id: string } }) {
try {
const id = parseInt(params.id);
if (isNaN(id)) {
return NextResponse.json({ error: 'Invalid tool ID' }, { status: 400 });
}
const tool = await getToolById(id);
if (!tool) {
return NextResponse.json({ error: 'Tool not found' }, { status: 404 });
}
return NextResponse.json({ tool });
} catch (error) {
console.error('Error fetching tool:', error);
return NextResponse.json({ error: 'Failed to fetch tool' }, { status: 500 });
}
}